package thread.method;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-03-05
 * Time:23:26
 */
public class Method1 {
    /*
    synchronized void setName(String name)  设置线程名称
    String getName()  返回该线程名称
    void start()  使该线程开始执行----JVM虚拟机底层调用start0()方法
    void run()  调用线程对象的run方法
    void setPriority(int newPriority)  更改线程的优先级
    int getPriority()  获得线程的优先级
    static void sleep(long millis) throws InterruptedException  在指定的毫秒内让当前正在执行的线程休眠----暂停执行
    void interrupt()  中断线程----中止休眠
     */
    public static void main(String[] args) throws InterruptedException {
        T1 t1 = new T1();
        t1.setName("zhangsan");
        t1.setPriority(Thread.MAX_PRIORITY);
        t1.start();
        Thread.sleep(1000*3);
        for (int i = 0; i < 10; i++) {
            System.out.println(i);
        }
        System.out.println(t1.getName() + "的优先级为:" + t1.getPriority());
        t1.interrupt();
    }
}
class T1 extends Thread{
    @Override
    public void run() {
        while(true) {
            for (int i = 0; i < 100; i++) {
                System.out.print("猪八戒在吃包子" + i);
                System.out.println("   该线程名为:" + Thread.currentThread().getName());
            }
            try {
                super.sleep(1000*20);
            } catch (InterruptedException e) {
                System.out.println(Thread.currentThread().getName() + "被中断");
            }
        }
    }
}
